package cn.com.hhrcw.web;

import cn.com.hhrcw.entity.SsSession;
import cn.com.hhrcw.mapstruct.SsSessionConvert;
import cn.com.hhrcw.params.SsSessionParams;
import cn.com.hhrcw.service.IOpDeliveryHistoryService;
import cn.com.hhrcw.service.IOpJobService;
import cn.com.hhrcw.service.ISsSessionService;
import cn.com.hhrcw.vo.SsSessionVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.function.Function;

/**
 * 专场-专场本场
 * 区块等简单情况使用
 * @author jiangdong
 * @since 2020-10-29
 */
@RestController
@Slf4j
@RequestMapping("/personal/ssSession2")
@Api(tags = "专场-专场本场")
@Validated
public class SsSession2Controller extends JeecgController<SsSession, ISsSessionService> {

    @Autowired
    private ISsSessionService ssSessionService;

    @Autowired
    private SsSessionConvert ssSessionConvert;
    @Autowired
    private IOpJobService jobService;
    @Autowired
    private IOpDeliveryHistoryService deliveryHistoryService;



    /**
     * 专场招聘-专场列表(原始)
     *
     * @param params 请求参数
     * @return
     */
    @GetMapping(value = "/list")
    @AutoLog("专场-专场本场-分页列表查询")
    @ApiOperation(value = "分页列表查询", notes = "分页列表查询")
    public Result<Page<SsSessionVO>> list(  SsSessionParams params, HttpServletRequest request) {


        QueryWrapper<SsSession> queryWrapper = QueryGenerator.initQueryWrapper(ssSessionConvert.toEntity(params), request.getParameterMap());
        queryWrapper.eq("del_flag", false);

        if (org.apache.commons.lang.StringUtils.isBlank(params.getField())) {
        } else {
            queryWrapper.orderBy(true, params.getSort(), toUnderlineName(params.getField()));
        }
        IPage<SsSession> page = ssSessionService.page(params.page(), queryWrapper);
        //分页结果转换器
        Function<SsSession, SsSessionVO> fun = ssSession -> ssSessionConvert.toVO(ssSession);

        return Result.ok((Page)page.convert(fun));

    }


}
